import docx
from docx.oxml.ns import qn

def readDocx(got):
    i = 0
    src = []
    styles=[]
    for st in got.styles:
        if not st.name.startswith(':'): continue
        if isinstance(st,docx.styles.style._CharacterStyle):
            for each in styles:
                if st.name[1:].startswith(each['style']):
                    font = st.font
                    each['font'] = font.name
                    each['fontSize'] = font.size
                    each['bold'] = font.bold
                    each['underline'] = font.underline
                    each['italic'] = font.italic
        if isinstance(st,docx.styles.style._ParagraphStyle):
            pick = {}
            pick['style'] = st.name[1:]
            pick['alignment'] = st.paragraph_format.alignment
            styles.append(pick)

    for paragraph in got.paragraphs:
        for run in paragraph.runs:
            src.append({
                'num': i,
                'style': run.style.name,
                'bold': run.bold,
                'fontSize': run.font.size,
                'font': run.font.name,
                'text': run.text,
                'paragraph': {
                    'bold': paragraph.style.font.bold,
                    'style': paragraph.style.name,
                    'italic': paragraph.style.font.italic,
                    'fontSize': paragraph.style.font.size,
                    'font': paragraph.style.font.name,
                    'alignment': paragraph.alignment
                }
            })
        i += 1
    return src,styles
